package com.irdstudio.tdp.executor.core.plugin.util;


import com.irdstudio.tdp.executor.core.plugin.util.bean.FileReplacePattern;
import com.irdstudio.tdp.executor.core.plugin.util.bean.ReplaceDirAndFileBean;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;

/**
 * <p>生成工程辅助类</p>
 * @author ligm
 * @date 2019-06-13
 */

public class ProjectGenerateUtil {
	
	private static Logger logger = LoggerFactory.getLogger(ProjectGenerateUtil.class);
			
    public static void main(String[] args) throws IOException {

        // 输入项
//        String srcFilePath = args[0];//"D:\\testCopyFile\\sample.example.front";
//        String outFilePath = args[1];//"D:\\testCopyFile\\efp.cus.front";
//        String srcStr = args[2];//"sample.example";
//        String replaceStr = args[3];//"efp.cus";
        
//        String srcFilePath = "E:\\Project\\irdstudio2\\esaas.console.all";
//        String outFilePath = "E:\\Project\\irdstudio3\\esaas.member.all";
//        String srcStr = "esaas.console";
//        String replaceStr = "esaas.member";
    	
        String srcFilePath = "esaas.member.all";
        String outFilePath = "efp.limit";
        String srcStr = "esaas.member";
        String replaceStr = "efp.limit";
        
        // 复制并重命名工程
        ProjectGenerateUtil.copyAndRenameProject(srcFilePath, outFilePath, srcStr, replaceStr);

    }
    
    /**
     * 复制并重命名工程
     * @param srcFilePath
     * @param outFilePath
     * @param srcStr
     * @param dstStr
     */
	public static void copyAndRenameProject(String srcFilePath, String outFilePath, String srcStr, String dstStr) {
		logger.info("从{}复制并重命令工程到{}...", srcFilePath, outFilePath);
		ReplaceDirAndFileBean rdfb = new ReplaceDirAndFileBean(srcFilePath, outFilePath, srcStr, dstStr);
		rdfb.addFileReplacePattern(new FileReplacePattern("*", srcStr.replace(".", "-"), dstStr.replace(".", "-")));
		rdfb.addFileReplacePattern(new FileReplacePattern("pom.xml", "irdstudio." + srcStr.split("\\.")[0],
				"irdstudio." + dstStr.split("\\.")[0]));
		rdfb.setIgnorePostfix("html,css,js");
		rdfb.execute();
		logger.info("从{}复制并重命令工程到{}完成!", srcFilePath, outFilePath);
    }

}
